<?php
// no direct access
defined('_JEXEC') or die;

// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

class JFormFieldCid extends JFormFieldList {
	protected $type = 'Cid';
	
	protected function getOptions() {
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('id, name, description');
		$query->from('#__icd10');
		$db->setQuery((string) $query);
		$codigos = $db->loadObjectList();
		$options = array();
		if ($codigos) {
			foreach ($codigos as $codigo) {
				$options[] = JHtml::_('select.option', $codigo->id, $codigo->name.' '.$codigo->description);
			}
		}
		$options = array_merge(parent::getOptions(), $options);
		return $options;
	}
}